/**
 * $Id: EditorKeyboardHandler.java,v 1.1 2009/10/23 11:32:08 gaudenz Exp $
 * Copyright (c) 2008, Gaudenz Alder
 */
package com.magnificent.panda.ui.editor;

import com.magnificent.panda.ui.GraphComponent;
import com.magnificent.panda.ui.handler.mxKeyboardHandler;
import com.magnificent.panda.ui.util.mxGraphActions;

import javax.swing.*;

/**
 * @author Administrator
 */
public class EditorKeyboardHandler extends mxKeyboardHandler {

    /**
     * @param graphComponent
     */
    public EditorKeyboardHandler(GraphComponent graphComponent) {
        super(graphComponent);
    }

    /**
     * Return JTree's input map.
     */
    protected InputMap getInputMap(int condition) {
        InputMap map = super.getInputMap(condition);

        if (condition == JComponent.WHEN_FOCUSED && map != null) {
            map.put(KeyStroke.getKeyStroke("control S"), "save");
            map.put(KeyStroke.getKeyStroke("control shift S"), "saveAs");
            map.put(KeyStroke.getKeyStroke("control N"), "new");
            map.put(KeyStroke.getKeyStroke("control O"), "open");

            map.put(KeyStroke.getKeyStroke("control Z"), "undo");
            map.put(KeyStroke.getKeyStroke("control Y"), "redo");
            map
                    .put(KeyStroke.getKeyStroke("control shift V"),
                            "selectVertices");
            map.put(KeyStroke.getKeyStroke("control shift E"), "selectEdges");
        }

        return map;
    }

    /**
     * Return the mapping between JTree's input map and JGraph's actions.
     */
    protected ActionMap createActionMap() {
        ActionMap map = super.createActionMap();

        map.put("save", new EditorActions.SaveAction(false));
        map.put("saveAs", new EditorActions.SaveAction(true));
        map.put("new", new EditorActions.NewAction());
        map.put("open", new EditorActions.OpenAction());
        map.put("undo", new EditorActions.HistoryAction(true));
        map.put("redo", new EditorActions.HistoryAction(false));
        map.put("selectVertices", mxGraphActions.getSelectVerticesAction());
        map.put("selectEdges", mxGraphActions.getSelectEdgesAction());

        return map;
    }

}

  /* converted to utf8 */